﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using Supersense.db;
using System.Data;

public partial class product_detail : System.Web.UI.Page
{
    public DataTable productCategory;
    public DataTable products;
    public DataTable[] hArray;



    protected void Page_Load(object sender, EventArgs e)
    {
        Crud modelCategory = new Crud("ss_category", "id");
        productCategory = modelCategory.fList("type='product' and upid=0", "", "", "");

        DataTable[] htArray = new DataTable[productCategory.Rows.Count];
        hArray = htArray;

        DataTable subCategory = modelCategory.fList("type='product' and upid!=0", "", "", "");
        for (int i = 0; i < productCategory.Rows.Count; i++)
        {
            htArray[i] = this.dealTable(subCategory, "upid", productCategory.Rows[i]["id"].ToString().Trim());
            //dt.Rows[i]["subCategory"] = this.dealTable(subCategory, "upid", dt.Rows[i].ToString());
        }

        Crud modelProduct = new Crud("ss_product", "id");
        products = modelProduct.fPk(Convert.ToInt32(Request.QueryString["id"]));

    }

    public DataTable dealTable(DataTable sourceTable, String key, String value)
    {
        DataTable ht = new DataTable();
        ht.Columns.Add("name");
        ht.Columns.Add("id");
        if (sourceTable == null)
        {
            return null;
        }
        foreach (DataRow dr in sourceTable.Rows)
        {
            if (dr[key].ToString().Trim() == value)
            {
                DataRow row = ht.NewRow();
                row["name"] = dr["name"].ToString();
                row["id"] = dr["id"].ToString();
                ht.Rows.Add(row);
            }
        }
        return ht;
    }
}